package cn.kmust.booth.portal.service.impl;


import cn.kmust.booth.portal.mapper.NoticeMapper;
import cn.kmust.booth.portal.model.Notice;
import cn.kmust.booth.portal.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class NoticeServiceImp implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public List<Notice> queryAll() {
        List<Notice> notices = noticeMapper.queryAll();
        return notices;
    }

    @Override
    public Notice queryById(Integer id) {
        Notice notice = noticeMapper.queryById(id);
        return notice;
    }

    @Override
    public List<Notice> queryByMan(Integer jobNumber) {
        return null;
    }

    @Override
    public String addNotice(Notice notice) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String time = dateTimeFormatter.format(now);
        notice.setNoticeTime(time);
        int i = noticeMapper.addNotice(notice);
        if (i==1){
            return "成功！";
        }
        return "错误！";
    }

    @Override
    public int updateNotice(Integer id) {
        return 0;
    }

    @Override
    public String deleteById(Integer id) {
        int result = noticeMapper.deleteById(id);
        if (result == 1){
            return "成功！";
        }
        return "失败！";
    }

    //请求全部的公告
}
